//
//  LangServiceViewController.m
//  YouthOlympic2014
//
//  Created by xiangpaopao on 14-7-17.
//  Copyright (c) 2014年 mitian. All rights reserved.
//

#import "LangServiceViewController.h"
#import "XYAlertView.h"

@interface LangServiceViewController ()

@property(nonatomic, strong)IBOutlet UIWebView *webView;

@end

@implementation LangServiceViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    for (UIView *view in [[[self.webView subviews] objectAtIndex:0] subviews]) {
        if ([view isKindOfClass:[UIImageView class]]) view.hidden = YES;
    }
    //self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"webbg"]];
    self.webView.backgroundColor = [UIColor clearColor];
    self.webView.opaque = NO;
    
    for (UIView *view in [[[self.webView subviews] objectAtIndex:0] subviews]) {
        if ([view isKindOfClass:[UIImageView class]]) view.hidden = YES;
    }
    [self.webView setScalesPageToFit:YES];
    
    
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
	[self.navigationController.view addSubview:HUD];
	HUD.labelText = @"请稍等...";
	
	HUD.delegate = self;

}

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    NSURL *url = inRequest.URL;
    NSString *urlString = url.absoluteString;
    
    NSLog(@"url %@", urlString);
    return YES;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [HUD show:YES];
    
    
	 NSString *webStr = @"http://res.airad.com/Olympic2014/service_lang.html";
    

    NSURL *url=[NSURL URLWithString:webStr];
    NSURLRequest *request=request=[NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [HUD hide:YES];
    self.title = [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}



- (IBAction)telAct:(id)sender
{
    XYAlertView *alertView = [XYAlertView alertViewWithTitle:@"拨打电话"
                                                     message:@"拨打多语言服务热线84243847?"
                                                     buttons:[NSArray arrayWithObjects:@"拨打", @"取消", nil]
                                                afterDismiss:^(int buttonIndex) {

                                                    
                                                    if (buttonIndex == 0) {
                                                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://84243847"]];

                                                    }
                                                    
                                                }];
    
    [alertView setButtonStyle:XYButtonStyleGray atIndex:1];
    
    [alertView show];
    
}



@end
